<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

use App\Repositories\Eloquent\MemberRepository;
use App\Repositories\Eloquent\ManageRepository;
use Auth, Hash, DB;

class DefaultController extends Controller
{
    protected $member, $manage;

    public function __construct(MemberRepository $member, ManageRepository $manage)
    {
        parent::__construct();

        $this->member = $member;

        $this->manage = $manage;

    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function login()
    {        
        return view($this->view);
    }


    /**
     * 会员登录
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function postLogin(Request $request) 
    {
        return $this->member->login($request);
    }

    
    public function recruit($uuid)
    {
        $member = $this->member->show($uuid);

        if ($member instanceof JsonResponse && $member->getStatusCode() === 404) {                    
            return abort('404');
        }

        return view($this->view, compact('member'));
    }


    public function postRecruit($uuid, Request $request)
    {
        return $this->member->recruit($uuid, $request);
    }


    public function success($uuid)
    {
        $member = $this->member->show($uuid);

        if ($member instanceof JsonResponse && $member->getStatusCode() === 404) {                    
            return abort('404');
        }

        return view($this->view, compact('member'));
    }


    public function content($type)
    {
        $content = $this->manage->content($type)->get()->first();

        return view($this->view, compact('content'));
    }

}
